﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Migraine.BLL
{
    class TrieuChungBUO:IBUO<tbl_TrieuChung>
    {
        BenhDataContext context = new BenhDataContext();
        public tbl_TrieuChung GetSingle(int id)
        {
            return context.tbl_TrieuChungs.Where(n => n.idTrieuChung == Convert.ToString(id)).ToList<tbl_TrieuChung>().FirstOrDefault();
        }

        public List<tbl_TrieuChung> GetAll()
        {
            return context.tbl_TrieuChungs.OrderByDescending(n => n.idTrieuChung).ToList<tbl_TrieuChung>();
        }

        public bool Insert(tbl_TrieuChung obj)
        {
            try
            {
                context.tbl_TrieuChungs.InsertOnSubmit(obj);
                context.SubmitChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool Update(int id, tbl_TrieuChung obj)
        {
            try
            {
                tbl_TrieuChung tc = context.tbl_TrieuChungs.Where(n => n.idTrieuChung == Convert.ToString(id)).ToList<tbl_TrieuChung>().FirstOrDefault();
                tc = obj;
                context.SubmitChanges();
                return true;

            }
            catch (Exception)
            {

                return false;
            }
        }
        public bool Delete(int id)
        {
            try
            {
                tbl_TrieuChung obj = context.tbl_TrieuChungs.Where(n => n.idTrieuChung == Convert.ToString(id)).First<tbl_TrieuChung>();
                if (obj != null)
                {
                    context.tbl_TrieuChungs.DeleteOnSubmit(obj);
                    context.SubmitChanges();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public bool Delete(tbl_TrieuChung obj)
        {
            throw new NotImplementedException();
        }
    }
}
